<?php

namespace App\Jobs;

use App\Helpers\PerFormanceTrait;
use App\Http\Controllers\Wechat\SendTemplateController;
use App\Models\Bill;
use App\Models\OnJobLog;
use App\Models\PerformanceTable;
use App\Models\StudentOffer;
use App\Models\SystemUser;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;

class SendPostCard implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PerFormanceTrait;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $postcard = StudentOffer::query()
            ->with('student')
            ->where('openid','<>','')
            ->where('status',1)
            ->where('send_time','<',now())
            ->get();
        foreach ($postcard as $v){
            (new SendTemplateController())->sendPostCardTemplate($v->openid,$v->student->name,$v->offer_image);
        }
        StudentOffer::query()
            ->with('student')
            ->where('openid','<>','')
            ->where('status',1)
            ->where('send_time','<',now())
            ->update(['status'=>2]);
    }
}
